﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL_Class;
using System.Text.RegularExpressions;

namespace NLLSite.UserControl
{
    public partial class MenuTop : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UIMenu objUIMenu = new UIMenu();
            IEnumerable<DAL_Class.Menu> objListMenus = objUIMenu.GetMenusTop();
            string strMenu = "";

            foreach (DAL_Class.Menu menu in objListMenus)
            {
                strMenu += "<li>";
                strMenu += "<a href=\"/tin-tuc/" + menu.ID + "/" + ConvertToUnSign(menu.Name) + "\" >" + menu.Name + "</a>";
                strMenu += "</li>";
            }
            strMenu += "";
            lblMenuTop.Text = strMenu;
        }
        public static string ConvertToUnSign(string text)
        {

            for (int i = 32; i < 48; i++)
            {

                text = text.Replace(((char)i).ToString(), " ");

            }

            text = text.Replace(".", "-");

            text = text.Replace(" ", "-");

            text = text.Replace(",", "-");

            text = text.Replace(";", "-");

            text = text.Replace(":", "-");



            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");



            string strFormD = text.Normalize(System.Text.NormalizationForm.FormD);

            return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D').ToLower();

        }
    }
}